﻿using System.IO;
using System.Text;

namespace IntypeSnippet2FingerText
{
	public class Program
	{
		public static void Main(string[] args)
		{
			const string IntypePath = @"C:\Program Files\Intype\bundles\PHP.itBundle\snippets";
			const string FingerTextPath = @"C:\Program Files\Notepad++\plugins\Intype.ftd";

			var files = Directory.GetFiles(IntypePath, "*.itSnippet");

			var sb = new StringBuilder();

			foreach (var file in files)
			{
				var snippet = GetSnippet(file);

				sb.Append(CreateFingerTextContent(snippet));
			}

			var content = sb.ToString();

			File.Delete(FingerTextPath);
			File.AppendAllText(FingerTextPath, content);
		}

		private static Snippet GetSnippet(string file)
		{
			var fileContent = File.ReadAllText(file);

			var snippet = new Snippet(fileContent);

			return snippet;
		}

		private static string CreateFingerTextContent(Snippet snippet)
		{
			/*
			template
			Makefile
			This is a makefile template.[>END<]
			!$[FingerTextData FingerTextData]@#
			 */

			var sb = new StringBuilder();

			sb.AppendLine(snippet.TabTrigger);
			sb.AppendLine(".php");
			sb.Append(snippet.Content);
			sb.AppendLine("[>END<]");
			sb.AppendLine("!$[FingerTextData FingerTextData]@#");

			var content = sb.ToString();

			return content;
		}
	}
}
